<?php
namespace Code\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $ip_city = detect_city('112.5.161.77');
        dump('IP为：'.$ip_city);
    }

    public function xml(){
        //this is a sample xml string
        $xml_string="<?xml version='1.0'?>
<moleculedb>
    <molecule name='Benzine'>
        <symbol>ben</symbol>
        <code>A</code>
    </molecule>
    <molecule name='Water'>
        <symbol>h2o</symbol>
        <code>K</code>
    </molecule>
</moleculedb>";

//load the xml string using simplexml function
        $xml = simplexml_load_string($xml_string);
        //preg_match_all('/<!\[CDATA\[(.*?)\]\]>/i', $xml_string, $a);//获取<![]>中的值
dump(json_encode($xml , true));die;
//loop through the each node of molecule
        foreach ($xml->molecule as $record)
        {
            //attribute are accessted by
            echo $record['name'], '  ';
            //node are accessted by -> operator
            echo $record->symbol, '  ';
            echo $record->code, '<br />';
        }
    }
}